home *** CD-ROM | disk | FTP | other *** search
- Path: news.cyberport.com!usenet
- From: tangent@cyberport.com (Warren Young)
- Newsgroups: comp.lang.c++
- Subject: Re: The STL and nested structures
- Date: Tue, 09 Apr 1996 09:02:09 GMT
- Organization: none
- Message-ID: <316a26d7.2989288@news.cyberport.com>
- References: <4ju9q7$fa1$1@mhadg.production.compuserve.com>
- NNTP-Posting-Host: ppp5.cyberport.com
- X-Newsreader: Forte Agent .99d/32.182
-
- Alan Huff <74312.2300@CompuServe.COM> wrote:
-
- >I am having a problem using the STL with structures defined within
- >a class definition. Consider the following code fragment.
- >
- >>#include <vector.h>
- >>class Bar {
- >> struct Foo {
- >> int value;
- >> };
- >>
- >> vector< Foo > fooContainer;
- >>}
- >
- >The compiler I am using (VC 4.1) refuses to compile. An error is
- >generated the says "'Foo' : undeclared identifier" at line 75 in
- >vector.h.
-
- It _is_ undeclared, just as a variable local to a function foo() is
- undeclared in a function bar(). What you want to say is:
-
- vector<Bar::Foo> fooContainer;
-
- Even this won't work until Foo is placed in the public section of the
- class (as shown above, it's in the private (default) section).
-
- I suspect that you're an ex-C programmer, because C treated nested
- structures as having the same scope. Not so in C++, and the language
- is better for it, IMO.
-
- = Warren --
-